﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Library.Bll;

namespace HanhuaMicroCredit.Admin.Controllers
{
    public class sysManageController : Controller
    {
        //
        // GET: /sysManage/
        #region //

        #endregion
        /// <summary>
        /// url
        /// </summary>
        /// <param name="n">1company,2department,3IBUsers,4outlets</param>
        /// <param name="m">1List,2Add,3Edit</param>
        /// <param name="k">1aspx,2cshtml</param>
        /// <returns></returns>
        private string getview(int n,int m,int k)
        {
            string view = "";
            string name = "";
            string asx = "";
            
            if (n == 1)
            {
                view = "~/views/sysManage/company/";
            }
            else if (n == 2)
            {
                view = "~/views/sysManage/department/";
            }
            else if (n == 3)
            {
                view = "~/views/sysManage/IBUsers/";
            }
            else if (n == 4)
            {
                view = "~/views/sysManage/outlets/";
            }
            if (m == 1)
            {
                name = "List";
            }
            else if(m==2)
            {
                name = "Add";
            }
            else if (m == 3)
            {
                name = "Edit";
            }
            if (k == 1)
            {
                asx = ".aspx";
            }
            else if (k == 2)
            {
                asx = ".cshtml";
            }

            return view+name + asx;
        }
        

        #region //总公司
        /// <summary>
        /// 公司列表
        /// </summary>
        /// <param name="pid">上级id</param>
        /// <returns></returns>
        public ActionResult list_1()
        {
            //ViewData["pid"] = pid;
            return View(getview(1,1,1));
        }
        /// <summary>
        /// 公司添加
        /// </summary>
        /// <param name="tree">1总公司,2分公司</param>
        /// <returns></returns>
        public ActionResult add_1(int tree)
        {
            if (tree == 0)//总公司
            {
                return View("~/views/sysManage/company/Add_1.aspx");
            }
            else
            {
                return View("~/views/sysManage/company/Add_2.aspx");
            }
        }
        public ActionResult edit_1(int id)
        {
            Dictionary<string, object> d = CommonBLL.GetModel("Sys_Company", "*", id);
            ViewData["id"] = id;
            if (d["tree"].ToString() == "0")
            {
                return View("~/views/sysManage/company/Edit_1.aspx",d);
            }
            else
            {
                return View("~/views/sysManage/company/Edit_2.aspx",d);
            }
        }
        #endregion

        #region //部门
        public ActionResult list_2()
        {
            return View(getview(2,1,1));
        }
        public ActionResult add_2()
        {
            return View(getview(2,2,1));
        }
        public ActionResult edit_2(int id)
        {
            ViewData["id"] = id;
            return View(getview(2,3,1));
        }

        #endregion

        #region //门店
        public ActionResult list_3()
        {
            return View(getview(4, 1, 1));
        }
        public ActionResult add_3()
        {
            return View(getview(4, 2, 1));
        }
        public ActionResult edit_3(int id)
        {
            ViewData["id"] = id;
            return View(getview(4, 3, 1));
        }

        #endregion

        #region //人员
        public ActionResult list_4()
        {
            return View(getview(3, 1, 1));
        }
        public ActionResult add_4()
        {
            return View(getview(3, 2, 1));
        }
        public ActionResult edit_4(int id)
        {
            ViewData["id"] = id;
            return View(getview(3, 3, 1));
        }
        #endregion


        public ActionResult Index()
        {
            return View();
        }

    }
}
